<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Options extends CI_Controller {

	function __construct()
	{
		parent::__construct();
		$this->load->helper('bantuan_helper');
		if(!$this->session->userdata('user_id') && !$this->session->userdata('user_display_name') ):
			redirect('backend');
		elseif($this->session->userdata('user_rule')!='Administrator'):
			redirect('backend/no_acces');
		endif;

	}

	function index()
	{
		$this->form_validation->set_rules('sitename', 'Nama Website','required');
		$this->form_validation->set_rules('admin_email', 'Email Admin','required|valid_email');
		$this->form_validation->set_rules('media_thumbnail_size', 'Thumbnail','required|numeric');
		$this->form_validation->set_rules('media_medium_height', 'Medium Height','required|numeric');
		$this->form_validation->set_rules('media_medium_width', 'Medium Width','required|numeric');
		$this->form_validation->set_rules('media_large_height', 'Large Height','required|numeric');
		$this->form_validation->set_rules('media_large_width', 'Large Width','required|numeric');
		$this->form_validation->set_rules('global_meta_description', 'Deskripsi Website','required|trim');
		$this->form_validation->set_rules('global_meta_keyword', 'Keyword','required|trim');
		
		if ($this->form_validation->run() == FALSE):
			$data['title'] = 'Options';
			$data['template'] = 'options/index';
			$this->load->view('backend/index',$data);
		else:
			$posts = $_POST ;
			foreach ($posts as $post =>$val):
				$data['option_value'] = mysql_real_escape_string(strip_tags($val));
				$this->db->where('option_name',$post)->update('tb_option',$data);
			endforeach;
			$this->session->set_flashdata('message_type','<div id="kotak" class="success">Data berhasil disimpan</div>');
			redirect('backend/options');
		endif;
	}

}